<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">

<head th:include="common">
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div class="modal fade" id="goodsModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    详情页面
                </h4>
            </div>
            <div class="modal-body">
                <form id="goodsForm" >
                    <input type="hidden" class="form-control" name="inforId" id="inforId">
                    <div class="input-group">
                        <span class="input-group-addon">商品名称</span>
                        <input type="date" class="form-control" name="createDate" id="createDate">
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">消息名称</span>
                        <input type="text" class="form-control" name="infoName" id="infoName">
                    </div>
                    <div class="input-group">
                        <span class="input-group-addon">消息描述</span>
                        <!-- <input type="text" class="form-control" name="infoName" id="infoName">-->
                        <textarea class="form-control" name="messageDescribe" id="messageDescribe" style="min-height: 50px;min-width: 70px;max-height: 50px; max-width: 70px;">

                        </textarea>
                    </div>

                    <!--场次档次详细信息-->
                    <div id="goodsLeave"></div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="addOrUpdate()">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<table id="goodsTable"></table>
</body>
<script>
    $('#goodsModal').on('hidden.bs.modal', function () {

        document.querySelector('#goodsForm').reset();

    });
    $(function(){
        queryMap();
    })
    function queryMap(){
        $("#goodsTable").bootstrapTable({
            url:"/goodsConsummer/queryGoodsMap",
            columns:[
                {field:"goodsCheckbox",checkbox:true},
                {field:"goodsName",title:"商品名称"},
                {field:"goodsStartTime",title:"开始时间"},
                {field:"goodsEndTime",title:"结束时间"},
                {field:"goodsPutTime",title:"上架时间"},
                {field:"goodsAdress",title:"详细地址"},
                {field:"goodsType",title:"演出类型",
                    formatter:function (value,row){
                        if(value==1){
                            return "线上";
                        }else {
                            return "线下";
                        }
                    }
                },
                {field:"goodsMainActor",title:"主要演员"},
                {field:"goodsTicketsVendibilityCount",title:"可售门票数"},
                {field:"goodsRecommendedDegree",title:"推荐度"},
                {field:"goodsActivityNumber",title:"系列活动号"},
                {field:"goodsImg",title:"商品图片",
                    formatter:function(value,row){
                        return "<img src='"+value+"'  style='width:50px;height:50px'/>"
                    }
                },
                {field:"caoz",title:"操作",
                    formatter:function(value,row){
                        if (row.goodsStatus ==1){
                            return 	'<button class="btn btn-primary btn-lg"  onclick="updateDownGoods('+row.goodsId+')">删除</button>'+
                                '<button class="btn btn-danger btn-lg" onclick="selectOneGoods('+row.goodsId+')" >详情</button>'
                        }
                    }
                }
            ],
            pagination:true,
            pageSize:10,
            pageList:[10,20],
            sidePagination:'server',
        })
    }

    function selectOneGoods(goodsId){
        location.href="/jumpPage/goodsDetails?id="+goodsId;
        $.ajax({
         //   url:"goodsConsummer/selectOneGoods",
            url:"/goodsConsummer/getGoodsById",
            data:{goodsId:goodsId},
            dataType:"json",
            success:function (data){
                //显示场次档次
                $("#goodsLeave")
                $("#goodsModal").modal("show")
                for(var i in data){
                    $("#goodsForm input").each(function(index,dom){
                        if (i==$(dom).attr("name")) {
                            $(dom).val(data[i])
                        }
                    })
                }
            },
            error:function (){
                alert("信息获取失败")
            }
        })
    }

    function updateDownGoods(goodsId){
        $.ajax({
            url:"goodsConsummer/downGoods",
            data:{goodsId:goodsId},
            success:function (){
                alert("删除成功");
                queryMap();
            },
            error:function (){
                alert("删除失败")
            }
        })
    }

</script>
</html>